from apps.api.baseapi import BaseApi
from asyncio import get_event_loop
from tes import Mysql
from pprint import pprint as pp

from aiohttp import ClientSession


class GetOfferApi(BaseApi):

    def __init__(self, *args):
        super().__init__(api_url="param2/1/com.alibaba.product/alibaba.product.add", timestamp=False, *args)


async def main(data):
    session = ClientSession()

    api = GetOfferApi("da6b13f7-3f28-4c7f-8ef0-05297498a019", session, "8910339")

    param = {
        "productType": data['biz_type'],
        "categoryID": data['category_id'],
        "attributes": eval(data['attributes']),
        "subject": "测试测试测试测试",
        "language": data['language'],
        "image": {"image": ['https://cbu01.alicdn.com/img/ibank/2020/093/953/13603359390_1055873337.jpg']},
        "skuInfos": eval(data['sku_infos'])[0],
        "webSite": 1688,
        "description": "123123"
    }

    await api.post(param)

    await session.close()


if __name__ == '__main__':
    my = Mysql()
    result = my.select("SELECT * FROM Alibb.`offer_product` WHERE product_id='613775067586'")
    my.close()

    pp(result[0])
    # print('\n'*5)
    # pp(eval(result[0]['sku_infos'])[0])

    loop = get_event_loop()
    loop.run_until_complete(main(result[0]))
